package com.mapforge.filechooser;

import java.io.File;
import java.util.HashSet;

import javax.swing.filechooser.FileFilter;

import com.mapforge.util.FileUtil;

public class SpecificExtensionFileFilter extends FileFilter {
	protected HashSet<String> hashset;
	protected String filterDescription;
	public SpecificExtensionFileFilter(){
		this(new String[]{});
	}
	public SpecificExtensionFileFilter(String[] strings) {
		this("", strings);
	}

	public SpecificExtensionFileFilter(String description, String[] strings) {
		hashset = new HashSet<String>();
		this.filterDescription = description;
		for (int i = 0; i < strings.length; i++) {
			hashset.add(strings[i].toLowerCase());
		}
	}

	public void setExtensions(String[] str) {
		hashset.clear();
		for (int i = 0; i < str.length; i++) {
			hashset.add(str[i].toLowerCase());
		}
	}

	public void addExtension(String ext) {
		hashset.add(ext.toLowerCase());
	}

	public void setDescription(String dsc) {
		filterDescription = dsc;
	}

	public boolean accept(File f) {
		return f.isDirectory()
				|| hashset.contains(FileUtil.getExt(f).toLowerCase());
	}

	public String getDescription() {
		return filterDescription;
	}

}
